package com.ruoyi.project.system.controller;

import java.util.List;
import java.util.Map;

import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.project.system.domain.CourseQuestionCfg;
import com.ruoyi.project.system.service.ICourseQuestionCfgService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.utils.poi.ExcelUtil;

/**
 * 课程练习配置Controller
 * 
 * @author ruoyi
 * @date 2020-10-07
 */
@RestController
@RequestMapping("/system/courseQuestionCfg")
public class CourseQuestionCfgController extends BaseController
{
    @Autowired
    private ICourseQuestionCfgService courseQuestionCfgService;

    /**
     * 查询课程练习配置列表，章节名臣去重
     */
    @GetMapping("/distinctList")
    public TableDataInfo distinctList(CourseQuestionCfg courseQuestionCfg)
    {
        startPage();
        List<Map<String,Object>> list = courseQuestionCfgService.selectCourseQuestionCfgDistinctList(courseQuestionCfg);
        return getDataTable(list);
    }

    /**
     * 查询课程练习配置列表
     */
    @PreAuthorize("@ss.hasPermi('system:cfg:list')")
    @GetMapping("/list")
    public TableDataInfo list(CourseQuestionCfg courseQuestionCfg)
    {
        startPage();
        List<Map<String,Object>> list = courseQuestionCfgService.selectCourseQuestionCfgList(courseQuestionCfg);
        return getDataTable(list);
    }

    /**
     * 导出课程练习配置列表
     */
    @PreAuthorize("@ss.hasPermi('system:cfg:export')")
    @Log(title = "课程练习配置", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(CourseQuestionCfg courseQuestionCfg)
    {
//        List<Map<String,Object>> list = courseQuestionCfgService.selectCourseQuestionCfgList(courseQuestionCfg);
//        ExcelUtil<CourseQuestionCfg> util = new ExcelUtil<CourseQuestionCfg>(CourseQuestionCfg.class);
//        return util.exportExcel(list, "cfg");
        return null;
    }

    /**
     * 获取课程练习配置详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:cfg:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Integer id)
    {
        return AjaxResult.success(courseQuestionCfgService.selectCourseQuestionCfgById(id));
    }

    /**
     * 新增课程练习配置
     */
    @PreAuthorize("@ss.hasPermi('system:cfg:add')")
    @Log(title = "课程练习配置", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CourseQuestionCfg courseQuestionCfg)
    {
        return toAjax(courseQuestionCfgService.insertCourseQuestionCfg(courseQuestionCfg));
    }

    /**
     * 修改课程练习配置
     */
    @PreAuthorize("@ss.hasPermi('system:cfg:edit')")
    @Log(title = "课程练习配置", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CourseQuestionCfg courseQuestionCfg)
    {
        return toAjax(courseQuestionCfgService.updateCourseQuestionCfg(courseQuestionCfg));
    }

    /**
     * 删除课程练习配置
     */
    @PreAuthorize("@ss.hasPermi('system:cfg:remove')")
    @Log(title = "课程练习配置", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Integer[] ids)
    {
        return toAjax(courseQuestionCfgService.deleteCourseQuestionCfgByIds(ids));
    }

    /**
     * 通过章节课程获取课程练习配置
     */
    @GetMapping(value = "courseCatalogId/{courseCatalogId}")
    public List<Map<String,Object>> getInfo(@PathVariable("courseCatalogId") Long courseCatalogId)
    {
        return courseQuestionCfgService.selectCourseQuestionCfgListByCourseCatalogId(courseCatalogId);
    }

    @DeleteMapping("courseCatalogId/{courseCatalogId}")
    public int deleteCourseQuestionCfgByCourseCatalogId(@PathVariable("courseCatalogId") Long[] courseCatalogIds)
    {
        return courseQuestionCfgService.deleteCourseQuestionCfgByCourseCatalogId(courseCatalogIds);
    }
}
